//
//  HCStatusCell.swift
//  Hweibome
//
//  Created by 何川 on 15/12/10.
//  Copyright © 2015年 hechuan. All rights reserved.
//

import UIKit
import SnapKit

let HCStatusCellMargin: CGFloat = 10

let HCStatusNameFontSize: CGFloat = 14

let HCStatusTimeFontSize: CGFloat = 10

let HCStatusContentFontSize: CGFloat = 15


class HCStatusCell: UITableViewCell {
    
    var toolBarTopConstraint:Constraint?

    var statusViewModel : HCStatusViewModel?{
        didSet{
            originalView.statusViewModel = statusViewModel
            statusToolBar.statusViewModel = statusViewModel
            
            //增加中心部分内容
            toolBarTopConstraint?.uninstall()
            
            if statusViewModel?.status?.retweeted_status != nil {
                retweetView.hidden = false
                retweetView.statusViewModel = statusViewModel
                
                statusToolBar.snp_updateConstraints(closure: { (make) -> Void in
                    self.toolBarTopConstraint = make.top.equalTo(retweetView.snp_bottom).constraint
                })
            }else {
                retweetView.hidden = true
                statusToolBar.snp_updateConstraints(closure: { (make) -> Void in
                    self.toolBarTopConstraint = make.top.equalTo(originalView.snp_bottom).constraint
                })
            }
        }
    }
    
    
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI(){
        contentView.backgroundColor = UIColor(white: 0.95, alpha: 1)
        contentView.addSubview(originalView)
        contentView.addSubview(retweetView)
        contentView.addSubview(statusToolBar)
        
        //原创微博
        originalView.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(contentView)
            make.top.equalTo(contentView).offset(8)
            make.trailing.equalTo(contentView)
           // make.height.equalTo(45)
        }
        
        // 微博内容
        retweetView.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(originalView)
            make.top.equalTo(originalView.snp_bottom)
            make.trailing.equalTo(originalView)
        }
        
        //底部的toolBar
        statusToolBar.snp_makeConstraints { (make) -> Void in
//            make.top.equalTo(retweetView.snp_bottom)
            self.toolBarTopConstraint = make.top.equalTo(retweetView.snp_bottom).constraint
            make.leading.equalTo(contentView)
            make.width.equalTo(contentView)
            make.height.equalTo(44)
        }
        // 非常重要,而约束不能少
        contentView.snp_makeConstraints { (make) -> Void in
            make.bottom.equalTo(statusToolBar)
            make.top.equalTo(self)
            make.leading.equalTo(self)
            make.trailing.equalTo(self)
        }
        
    }
    private lazy var originalView:  HCStatusOriginalView = {
        let view = HCStatusOriginalView()
        view.backgroundColor = UIColor.whiteColor()
        return view
    }()
    private lazy var statusToolBar: HCStatusToolBar = HCStatusToolBar()
    private lazy var retweetView:HCStatusRetweetView = HCStatusRetweetView()

}
